
//https://www.acwing.com/problem/content/1251/

//并查集

#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N=2e4+10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
int n,m,q;
int p[N]; 

int find(int x)
{
    if (p[x] != x) p[x] = find(p[x]);
    return p[x];
}

int main()
{
	close();
	cin>>n>>m;

	for (int i = 1; i <= n; i++) p[i] = i;
	while(m--)
	{
		int a,b;
		cin>>a>>b;
		p[find(a)] = find(b);
	}

	cin>>q;
	while(q--)
	{
		int a,b;
		cin>>a>>b;
		if(find(a)==find(b)) cout<<"Yes"<<'\n';
		else cout<<"No"<<'\n';
	}

	return 0;
}